CXX:=/depot/gcc-4.2.2/bin/g++

DEBUG:=0
RSA_EXE:=rsa
TEST_EXE:=rsa_test

SRCS := $(wildcard *.cpp)
HEADERS := $(wildcard *.hpp)
OBJS := $(patsubst %.cpp, %.o, $(SRCS))

TEST_SRCS= $(wildcard test*.cpp) XP.cpp
TEST_OBJS := $(patsubst %.cpp, %.o, $(TEST_SRCS))

.PHONY: compile link
all: compile link

.PHONY: check-syntax
check-syntax:
	$(CXX) $(CXXFLAGS) -c $(CHK_SOURCES)

clean:
	rm -f *.o *.d *.so *.out *.cpp.*.* *.repo *.a $(TEST_EXE) $(RSA_EXE)

level=3
ifeq ($(DEBUG), 1)
CXXFLAGS += -g$(level) -ggdb$(level)
else
CXXFLAGS += -O3 -DNDEBUG
endif
CXXFLAGS +=-fPIC -Wall -m32

LDFLAGS := -m32

compile: $(OBJS) $(SRCS) $(HEADERS)
link: link_test_exe link_rsa

link_test_exe: $(TEST_OBJS)
	$(CXX) $(LDFLAGS) -rdynamic $^ -o $(TEST_EXE)

link_rsa: rsa.o
	$(CXX) $(LDFLAGS) -rdynamic $^ -o $(RSA_EXE)

%.o: %.cpp
	$(CXX) $(CXXFLAGS) -MMD -c $< -o $@
